import Loading from "@/components/Loading";
import BottomTabBar from "@/components/TabBar";
import EventBus from "@/utils/EventBus";
import { Suspense, useEffect } from "react";
import { Outlet, useNavigate } from "react-router-dom";

export default function App() {
    const navigate = useNavigate()
    let token = localStorage.getItem('token')
    useEffect(() => {
        // 如果 没有登录 ，我们可以在这里进行拦截
        if (!token) {
            // 跳转到登录页
            navigate('/login')
        }
    })

    // 这里面对登录超时事件进行注册
    EventBus.on('loginTimeout', () => {
        navigate('/login')
    })
    return <>
        {
            token && <>
                <Suspense fallback={<Loading />}>
                    <Outlet />
                </Suspense>
                <BottomTabBar />
            </>
        }
    </>
}